package com.qiantu.phone.ui.adapter;

import android.content.Context;
import android.view.ViewGroup;
import android.widget.ImageView;

import androidx.annotation.NonNull;

import com.qiantu.phone.R;
import com.qiantu.phone.app.AppAdapter;

public class ThemeViewpagerAdapter extends AppAdapter<Integer> {

    public ThemeViewpagerAdapter(Context context) {
        super(context);
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new ViewHolder();
    }

    private final class ViewHolder extends AppAdapter<?>.ViewHolder {

        private ViewHolder() {
            super(R.layout.item_theme_switch);
        }

        @Override
        public void onBindView(int position) {
            position = position % getData().size();
            Integer resId = getItem(position);
            ((ImageView)itemView).setImageResource(resId);
        }
    }

    @Override
    public int getItemCount() {
        return getData() == null || getData().size() == 0 ? 0 : Integer.MAX_VALUE;
    }
}
